new Vue({
    el: '#app',
    data() {
      return {
        form: { // 分页查询条件
          SQLSerialNumber: 't_supply_order',
          PaginationNumber: 1,
          RowAmount: 10,
          Condition: utf8ToBase64('%%,%%'),
          ExtensionCondition: utf8ToBase64(`AND supply_order.Enterprise_Info_SerialNumber='${getCookie('enterprise')}'
          AND supply_order.Creater_SerialNumber='${getCookie('user')}'`),
        },
        tableData: [],
        type: [{
          label: '全部',
          value: ''
        }, {
          label: '待审核',
          value: '0'
        }, {
          label: '已通过',
          value: '2'
        }, {
          label: '拒绝',
          value: '3'
        }],//类别
        total: 0,//总条数
        loading: false,// 节流阀门
      }
    },
    beforeCreate() {
      function setRem() {
        const designWidth = 750; // 设计稿宽度（rpx）
        const maxWidth = 540; // 可选：限制最大宽度（如手机端常见值）
        const screenWidth = Math.min(window.innerWidth, maxWidth);
        const scale = screenWidth / designWidth;
        document.documentElement.style.fontSize = scale + 'px';
      }
      setRem();//1rem = 0.5px 对标小程序在 375px 宽的屏幕上，1rpx = 0.5px（因为 750rpx / 375px = 2）
    },
    mounted() {
      this.init();
    },
    computed: {
      tagCss() {
        return function(item) {
          if (item.Row_Status == '0') {
            return { type:'warning', label:'待审核' }
          } else if (item.Row_Status == '3') {
            return { type:'danger', label:'拒绝' }
          } else {
            return { type:'success', label:'已通过' }
          }
        }
      }
    },
    methods: {
      async init(callback) {
        await Promise.allSettled([
          this.getList(this.form),
        ]);
        callback ? callback() : null;
      },
      handleChange(item) { // 切换类别
        this.form.PaginationNumber = 1; // 初始化
        this.form.Condition = utf8ToBase64(`%%,%${item.value}%`);
        this.tableData = [];
        this.getList(this.form);
      },
      handleDetail(item) {//跳转页面
        window.location.href = `../my/my-supply-detail.html?id=${item.Supply_Unit_Price_SerialNumber}&ids=${item.Supply_Order_SerialNumber}&type=1`;
      },
      async getList(data) { // 分页查询
        if (this.loading) return;
        this.loading = true;//开启节流
        try {
          const res = await generalApi.generalPaginationQueryBySQLSerialNumber(data);
          this.tableData = [...this.tableData, ...res.Rows];
          this.total = res.TotalRows;
        } catch (error) {
          console.error(error);
        }
        this.loading = false;//关闭节流
      },
      handleScroll(e) { // 滚动监听
        const { scrollTop, clientHeight, scrollHeight } = e.target;
        if (scrollTop + clientHeight >= scrollHeight && !this.loading && this.tableData.length < this.total) {
          this.form.PaginationNumber++;
          this.getList(this.form)
        }
      },
  
    },
  })
  